package com.hefei.blog.plugin.example;
//package mblog.plugin.example;
//
//import java.util.List;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import mblog.base.utils.cookie.BlogCookieConsts;
//import mblog.base.utils.cookie.BlogCookieUtil;
//import mblog.core.data.AccountProfile;
//import mblog.core.data.Post;
//import mblog.core.hook.interceptor.desk.GroupVidewControllerHook;
//import mblog.core.persist.service.CommentService;
//
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.method.HandlerMethod;
//import org.springframework.web.servlet.ModelAndView;
//
//import com.hefei.frontend.framework.http.request.CommonParameterThreadLocal;
//
///**
// * @author Beldon
// */
//@Component
//public class HidenContentPugin implements GroupVidewControllerHook.GroupViewControllerInterceptorListener {
//    @Autowired
//    private CommentService commentService;
//
//
//    @Override
//    public void preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) throws Exception {
//
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, ModelAndView modelAndView) throws Exception {
//        Post ret = (Post) modelAndView.getModelMap().get("ret");
//        if (check(request,ret.getId(),ret.getAuthor().getId())) {
//            Post post = new Post();
//            BeanUtils.copyProperties(ret, post);
//            post.setContent(replace(post.getContent()));
//            modelAndView.getModelMap().put("ret", post);
//        }
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception ex) throws Exception {
//
//    }
//
//    @Override
//    public void afterConcurrentHandlingStarted(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler) throws Exception {
//
//    }
//
//    private String replace(String content) {
//        String c = content.replaceAll("<hide>([\\s\\S]*)</hide>", "隐藏内容，请回复后查看");
//        c = c.replaceAll("&lt;hide&gt;([\\s\\S]*)&lt;/hide&gt;", "隐藏内容，请回复后查看");
//        return c;
//    }
//
//    private boolean check(HttpServletRequest request,long id,long userId) throws Exception {
//        if (CommonParameterThreadLocal.getUserId() == userId) {
//            return false;
//        }
//        List l = commentService.findByHql("from mblog.core.persist.entity.CommentPO where authorId = '"+CommonParameterThreadLocal.getUserId()+"' and toId = '"+id+"'");
//        if (l.size() > 0) {
//            return false;
//        }
//        return true;
//    }
//}
